package com.hdsx.restful.glzt.structure.zcz.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.esri.arcgis.geometry.IGeometry;
import com.hdsx.ao.base.BaseOpearte;
import com.hdsx.restful.glzt.roadline.lxxx.bean.Znode;
import com.hdsx.restful.glzt.structure.ql.bean.IntValueName;
import com.hdsx.restful.glzt.structure.ql.bean.StatisticalResult;
import com.hdsx.restful.glzt.structure.zcz.bean.Zcz;
import com.hdsx.restful.glzt.structure.zcz.mapper.ZczMapper;
import com.hdsx.restful.glzt.structure.zcz.service.ZczServer;
import com.hdsx.restful.util.Dao;
/**
 * ZczServer实现类
 *
 */
@Service
public class ZczServerImpl  extends BaseOpearte<Zcz> implements ZczServer {

	public ZczServerImpl() {
		super("GIS_ZCZ");
	}

	@Resource(name="zczMapper")
	private ZczMapper mapper;

	@Override
	public Zcz getById(String id) {
		return mapper.queryOne(id);
	}

	@Override
	public boolean addZcz(Zcz zcz) {
		return mapper.add(zcz)>0;
	}

	@Override
	public boolean updateZcz(Zcz zcz) {
		return mapper.update(zcz)>0;
	}

	@Override
	public boolean deleteById(String id) {
		return mapper.delete(id)>0;
	}

	@Override
	public Zcz getOne(String zczbm) {
		return mapper.queryOne(zczbm);
	}

	@Override
	public int queryCount(String lxbm,String xzqhbm,String sxxfx,Double qdzh,Double zdzh,String name) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("sxxfx", sxxfx);
		parameter.put("qdzh", qdzh);
		parameter.put("zdzh", zdzh);
		parameter.put("name", name);
		return mapper.selectCount(parameter);
	}
	@Override
	public List<Zcz> queryList(String lxbm,String xzqhbm,String sxxfx,Double qdzh,Double zdzh,String name,int begin, int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("sxxfx", sxxfx);
		parameter.put("qdzh", qdzh);
		parameter.put("zdzh", zdzh);
		parameter.put("name", name);
		parameter.put("begin", begin);
		parameter.put("end", end);
		List<Zcz> lists=mapper.selectList(parameter);
		return lists;
	}

	@Override
	public int queryZczCountXzqhbm(String xzqhbm) {
		// TODO Auto-generated method stub
		if(xzqhbm!=null){
			if(xzqhbm.endsWith("0000")){
				xzqhbm=xzqhbm.substring(0,2);
			}else if(xzqhbm.endsWith("00")){
				xzqhbm=xzqhbm.substring(0,4);
			}
		}
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("xzqhbm", xzqhbm);
		return mapper.countByXzqhbm(parameter);
	}

	@Override
	public List<Zcz> getListByXzqhbm(String xzqhbm, int begin, int end) {
		if(xzqhbm!=null){
			if(xzqhbm.endsWith("0000")){
				xzqhbm=xzqhbm.substring(0,2);
			}else if(xzqhbm.endsWith("00")){
				xzqhbm=xzqhbm.substring(0,4);
			}
		}
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("begin", begin);
		parameter.put("end", end);
		return mapper.selectListByXzqhbm(parameter);
	}

	@Override
	public List<Zcz> getListByLxbm(String lxbm, int begin, int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("begin", begin);
		parameter.put("end", end);
		return mapper.selectListByLxbm(parameter);
	}

	@Override
	public int queryZczCountByLxbm(String lxbm) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		return mapper.countByLxbm(parameter);
	}

	@Override
	public List<Dao> getShapeById(String id) {

		Zcz zcz = mapper.getShapeById(id);
		IGeometry shape=selectShape("ID='"+id+"'");
		zcz.setShape(shape);
		List<Dao> lists=new ArrayList<Dao>();
		lists.add(new Dao("治超站名称",zcz.getZczmc(),zcz.getPtx(),zcz.getPty()));
		lists.add(new Dao("治超站编码",zcz.getZczbm()));
		lists.add(new Dao("所在路线",zcz.getLxbm()));
		lists.add(new Dao("定位桩号",zcz.getDwzh()));
		lists.add(new Dao("站点级别",zcz.getZdjb()));
		return lists;
	}
	
	@Override
	public StatisticalResult countByParameter(Map<String,Object> map) {
		List<IntValueName> serieZczata = mapper.countTotalByParameter(map);
		List<String> legendData = mapper.selectClassify(map);
		StatisticalResult sr = new StatisticalResult();
		sr.setChartsText("治超站统计");
		sr.setSeriesData(serieZczata);
		sr.setLegendData(legendData);
		return sr;
	}
	@Override
	public List<Znode> zczNode() {
		List<Znode> zczNode = mapper.zczNode();
		return zczNode;
	}
	
	 @Override
	 public int countTotal(Map<String, Object> map){
		 return mapper.countTotal(map);
	 }
	 
	 @Override
	 public List<Zcz> listAll(String lxbm,String xzqhbm,String sxxfx,Double qdzh,
			Double zdzh,String name) {
		return mapper.listAll(lxbm,xzqhbm,sxxfx,qdzh,zdzh,name);
	 }
	 @Override
	public Zcz queryById(String id) {
			return mapper.selectById(id);
	}
	/**
	 * 分类细节
	 */
	@Override
	public List<Zcz> detail(Map<String, Object> map){
		return mapper.detail(map);
	}
	@Override
	public int countDetail(Map<String, Object> map) {
		return  mapper.countDetail(map);
	}
	@Override
	public List<String> selectName(String name){
		return mapper.selectName(name);
	}
}
